home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / ZTIMER11.ARJ / MAIN.CPP < prev    next >
C/C++ Source or Header  |  1992-04-21  |  2KB  |  92 lines

  1. /****************************************************************************
  2. *
  3. *                                 Zen Timer
  4. *
  5. *                               From the book
  6. *                         "Zen of Assembly Language"
  7. *                            Volume 1, Knowledge
  8. *
  9. *                             by Michael Abrash
  10. *
  11. *                    Simple Test program by Kendall Bennett
  12. *
  13. * Filename:        $RCSfile: main.cpp $
  14. * Version:        $Revision: 1.1 $
  15. *
  16. * Language:        C++ 2.1
  17. * Environment:    MS DOS (IBM PC)
  18. *
  19. * Description:    Test program for the Zen Timer Library C++ interface.
  20. *
  21. * $Id: main.cpp 1.1 92/04/20 17:34:22 kjb release $
  22. *
  23. * Revision History:
  24. * -----------------
  25. *
  26. * $Log:    main.cpp $
  27. * Revision 1.1  92/04/20  17:34:22  kjb
  28. * Initial revision
  29. ****************************************************************************/
  30.  
  31. #include <iostream.h>
  32. #include <dos.h>
  33. #include "ztimer.h"
  34.  
  35. #define    DELAY_SECS    10
  36.  
  37. /*-------------------------- Implementation -------------------------------*/
  38.  
  39. int        i,j;                                /* NON register variables! */
  40.  
  41. int main(void)
  42. {
  43.     PZTimer        ptimer;
  44.     LZTimer        ltimer;
  45.     ULZTimer    ultimer;
  46.  
  47.     /* Test the precision timer routine */
  48.  
  49.     for (j = 0; j < 5; j++) {
  50.         ptimer.start();
  51.         for (i = 0; i < 10000; i++)
  52.             i = i;
  53.         ptimer.stop();
  54.         }
  55.     cout << "Count: " << ptimer.count() << endl;
  56.     cout << "Time: " << ptimer << " secs\n";
  57.  
  58.     /* Test the precision timer routine for overflow */
  59.  
  60.     ptimer.restart();
  61.     for (j = 0; j < 10; j++)
  62.         for (i = 0; i < 20000; i++)
  63.             i = i;
  64.     ptimer.stop();
  65.     cout << "Count: " << ptimer.count() << endl;
  66.     cout << "Time: " << ptimer << " secs\n";
  67.  
  68.     /* Test the long period Zen Timer (we don't check for overflow coz
  69.      * it would take tooooo long!)
  70.      */
  71.  
  72.     ltimer.start();
  73.     for (j = 0; j < 10; j++)
  74.         for (i = 0; i < 20000; i++)
  75.             i = i;
  76.     ltimer.stop();
  77.     cout << "Count: " << ltimer.count() << endl;
  78.     cout << "Time: " << ltimer << " secs\n";
  79.  
  80.     /* Test the ultra long period Zen Timer */
  81.  
  82.     ultimer.start();
  83.     delay(DELAY_SECS * 1000);
  84.     ultimer.stop();
  85.     cout << "Delay of " << DELAY_SECS << " secs took " << ultimer.count()
  86.          << " 1/10ths of a second\n";
  87.     cout << "Time: " << ultimer << " secs\n";
  88.  
  89.     return 0;
  90. }
  91.